import ADQ from "../../ADCore/Core/ADQ";
import HttpGloableConfig from "../../ADCore/Network/HttpGloableConfig";
import { JSONObject } from "../../ADCore/Common/JSONReturn"; 

/**授权逻辑 */
export default class AuthHelper {
    static userInfo:any;//用户信息
    static userData:any;//用户数据

    /**快速注册并登录 */
    fastRegister() {

    }
    /**
     * 登录操作
     * @param userName 
     * @param password 
     * @param callback 回调函数，参数（result） 
     */
    login(userName, password, callback) {
        ADQ.Http.post("/api/token/login", { clientId: "admin", userName: userName, password: password }).then(function (result: any) {     
            if (result.success) {
                ADQ.storage.setJSON("token", result.data);
                HttpGloableConfig.headers.common["Authorization"] = "bearer " + result.data.token;
                callback(result);
            }
            else {

            }
        }).catch(function (err) {
            var result = new JSONObject();
            result.success = false;
            result.msg = "网络错误！";
            callback(result);
        });
    }
 
    bindData() {
       
    }
    /**普通注册 */
    register() {

    }
}